<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends MX_Controller {
  function __construct() {
    $this->load->model('login/mlogin');
    $this->load->library('encrypt');
    $this->load->library('form_eksternal');
    $this->load->library('global_models');
    $this->load->library('nbscache');
//    $this->load->library('parser');
    $this->load->library('form_validation');
    $this->load->helper('path');
    $this->load->helper('url');
    $this->load->library('session');
    $this->session->unset_userdata('logged_in');
  }
	public function index($pesan = "hal"){
//    $this->debug($_SERVER, true);
    $config = array(
      array(
            'field'   => 'memuname', 
            'label'   => 'Username', 
            'rules'   => 'required'
         ),
      array(
            'field'   => 'mempass', 
            'label'   => 'Password', 
            'rules'   => 'required'
         ),
    );
    
    $this->form_validation->set_rules($config);
    $this->template->title('Login', "Sistem");
    if ($this->form_validation->run() == FALSE){
//      print "gagal";
			$this->template->build('main', 
        array('message' => $pesan,
              'url'     => base_url()."themes/srabon/",
              'field'   => array('memuname' => $this->input->post('memuname'))
            ));
      $this->template
        ->set_layout('login')
        ->build('main');
		}
		else{
      $cek_login = $this->mlogin->cek_login($this->input->post('memuname'), $this->input->post('mempass'));
//      $this->debug($cek_login, true);
      if($cek_login === true){
        redirect($this->session->userdata('dashbord'));
      }
      else{
        $this->template->build('main', 
        array('message' => "gagal",
              'url'     => base_url()."themes/srabon/",
              'field'   => array('memuname' => $this->input->post('memuname'))
            ));
      $this->template
        ->set_layout('login')
        ->build('main');
      }
		}
	}
}